package xyz.molzhao.cfapi;

import xyz.molzhao.util.CommonUtil;

import java.util.concurrent.CompletableFuture;

/**
 * 开启异步任务
 *
 * 场景：
 * 小明进门点菜，点完菜之后厨师开始做菜，同时小明打王者进行等待
 * 等厨师做完菜之后小明开始吃饭
 */
public class OpenAsync {
    public static void main(String[] args) {
        CommonUtil.createBehavior("小明进门");
        CommonUtil.createBehavior("小明点了 番茄炒蛋 + 饭");

        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
            CommonUtil.createBehavior("厨师做菜", 1000);
            return "番茄炒鸡蛋";
        });

        CommonUtil.createBehavior("小明玩王者");
        CommonUtil.createBehavior(String.format("小明吃%s", future.join()));
    }
}
